<?php
    @header("Content-Type:text/html;charset=utf-8");

    function argErr(){
        $msg = array();
        $msg["status"] = false;
        $msg["detail"] = "请传入完整参数";
        exit(json_encode($msg));
    }

     // $key = "字段名" 
    function isExist($key){
        global $conn;  //!!!! 允许局部变量访问全局变量

        $val = $_GET[$key];  // 根据字段名 获取对应的值
        if(!$val){  // 如果没有值就报错
            argErr();
        }
        
        $search = "select * from `userinfo_mz` where $key = '$val'";
        // echo $search;

        $result = mysqli_query($conn,$search);

        $item =  mysqli_fetch_assoc($result); 

        $msg = array();
        $list = array("user"=>"用户名","phone"=>"手机号");

        if(!$item){  
            $msg["status"] = true;
            $msg["detail"] = "可以使用的".$list[$key];
        }else{    // 存在该用户
            $msg["status"] = false;
            $msg["detail"] = $list[$key]."已注册";
        }
        echo json_encode($msg);
    }


      /**
      * 分割中文字符串
      * $string 字符串
      * $len 长度
    */ 
    function mbStrSplit($string, $len=1) {
        $start = 0;
        $strlen = mb_strlen($string);
        $array = array();
        while ($strlen) {
            $char  = mb_substr($string,$start,$len,"utf8");
            array_push($array,$char);
            $string = mb_substr($string, $len, $strlen,"utf8");
            $strlen = mb_strlen($string);
        }
        return $array;
    }





?>